﻿@model List<BDShop.Entities.ProductCacheComplex>
@using BDShop.Configuration
@using BDShop.Library.Extensions
@using BDShop.Utilities.Managers

<section class="box">
    <div class="box-heading">SẢN PHẨM SHOP ĐỀ CỬ</div>
    <div class="box-content">
        <div class="box-product">
            <div class="flexslider featured_carousel">
                <ul class="slides">
                    @foreach (var product in Model)
                    {
                        string[] categoryDefinition = null;
                        if (!string.IsNullOrEmpty(product.CategoryDefinition))
                        {
                            categoryDefinition = product.CategoryDefinition.Split('|')[0].Split('#');
                        }
                        var url = UrlManager.ProductDetailUrl(product.ID, product.Name, categoryDefinition);
                        <li>
                            <div class="slide-inner">
                                <div class="image">
                                    <a href="@url">
                                        <img class="lazy" data-original="@Path.Combine(BDShopConfiguration.Storage.MainImagePath, product.MainImage)" src="@Path.Combine(BDShopConfiguration.Storage.MainImagePath, product.MainImage)" alt="@product.Name" /></a>
                                </div>
                                <div class="name"><a href="@url">@product.Name</a></div>
                                <div class="price">
                                    @if (product.DiscountPrice == 0)
                                    {
                                        <span class="price-new">@product.Price.ToCurrencyString(false, true)</span> 
                                    }
                                    else
                                    {
                                        <span class="price-old">@product.MarketPrice.ToCurrencyString(false, true)</span> <span class="price-new">@product.Price.ToCurrencyString(false, true)</span> 
                                    }
                                </div>
                                <div class="cart">
                                    <input type="button" value="Mua hàng" class="button" onclick="window.location.href='@url'" />
                                </div>
                                <div class="clear"></div>
                            </div>
                        </li>
                    }
                </ul>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript">
    (function () {
        // store the slider in a local variable
        var $window = $(window),
            flexslider;

        // tiny helper function to add breakpoints
        function getGridSize() {
            return (window.innerWidth < 320) ? 1 :
                (window.innerWidth < 600) ? 2 :
                    (window.innerWidth < 800) ? 3 :
                        (window.innerWidth < 900) ? 4 : 5;
        }
        $window.load(function () {
            $('#content .featured_carousel').flexslider({
                animation: "slide",
                animationLoop: false,
                slideshow: false,
                itemWidth: 210,
                minItems: getGridSize(), // use function to pull in initial value
                maxItems: getGridSize() // use function to pull in initial value
            });
        });
    }());

</script>
